package org.code;

import java.util.Iterator;

public class Lt284 {

}


class PeekingIterator implements Iterator<Integer> {

	private Integer nextVal;
	private Iterator<Integer> iterator;

	public PeekingIterator(Iterator<Integer> iterator) {
	    // initialize any member here.
		this.iterator = iterator;
		
		if(this.iterator.hasNext()) {
			nextVal= this.iterator.next();
		}
	}

    // Returns the next element in the iteration without advancing the iterator.
	public Integer peek() {
		return nextVal;
	}

	// hasNext() and next() should behave the same as in the Iterator interface.
	// Override them if needed.
	@Override
	public Integer next() {
		int next = nextVal;
		nextVal = iterator.hasNext()?iterator.next():null;
		return next;
	}

	@Override
	public boolean hasNext() {
		return nextVal!=null;
	}
}